package cn.yitun.chat.yitunserverimapicore.business.contact.action;

import cn.yitun.chat.yituncommonmessage.ExceptionEnum;
import cn.yitun.chat.yituncommonmessage.YitunException;
import cn.yitun.chat.yituncommonmessage.result.ResultMessage;
import cn.yitun.chat.yituncommonutil.YitunCollectionUtil;
import cn.yitun.chat.yitungeneral.annotation.action.ActionMapping;
import cn.yitun.chat.yitungeneral.annotation.parameter.JsonDefine;
import cn.yitun.chat.yitunnetsession.session.SocketSession;
import cn.yitun.chat.yitunservercommonlib.constant.ActionTypeConstant;
import cn.yitun.chat.yitunservercommonlib.dataentity.dto.contact.ContactHarassSettingDto;
import cn.yitun.chat.yitunservercommonlib.dataentity.vo.contact.ContactAddVerifyQuestionVo;
import cn.yitun.chat.yitunservercommonlib.dataentity.vo.contact.ContactHarassSettingVo;
import cn.yitun.chat.yitunserverimapicore.business.contact.service.HarassSettingService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * Date 2019-01-20 11:55:08<br>
 * Description 防骚扰设置
 *
 * @author yitun<br>
 * @version 1.1
 */
@Component
@ActionMapping(value = ActionTypeConstant.HARASS_SETTING_ACTION_PUSH)
public class HarassSettingAction {

	@Resource
	private HarassSettingService harassSettingService;

	/**
	 * 获取详情
	 * @param socketSession
	 * @return
	 */
	@ActionMapping(value = "1.1.0001")
	public ResultMessage getDetail(
			SocketSession socketSession) {
		Long userId = socketSession.getKey();
		ContactHarassSettingVo setting = harassSettingService.getByUserId(userId);
		List<ContactAddVerifyQuestionVo> list = harassSettingService.getVerifyQuestionListByUserId(userId);
		ResultMessage message = new ResultMessage();
		message.bodyPut("setting", setting);
		message.bodyPut("questionList", list);
		return message;
	}

	@ActionMapping(value = "1.1.0002")
	public Object updateSetting(
			SocketSession socketSession,
			@JsonDefine("data") ContactHarassSettingDto query) {
		if (YitunCollectionUtil.isEmpty(query.getQuestionList()))
			throw new YitunException(ExceptionEnum.LOSE_FILED);

		query.setUserId(socketSession.getKey());
		ResultMessage message = new ResultMessage();
		message.setInfo(harassSettingService.saveOrUpdate(query));
		return message;
	}
}
